"""
  模块描述：短信模块报告接收-参数
  @author 8522
  @date 2022-05-17 17:57:38
  版权所有 Copyright www.dahantc.com
"""
from common.util import EntityUtil

# 短信上行消息报告参数
class SmsDeliverData:
    # 回复手机号码
    phone = ""

    # 手机回复短信内容
    content = ""

    # 子号码
    subcode = ""

    # 回复时间，格式yyyy-MM-dd HH:mm:ss
    delivertime = ""

    def __init__(self, phone, content, subcode, delivertime):
        self.phone = phone
        self.content = content
        self.subcode = subcode
        self.delivertime = delivertime

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return SmsDeliverData(EntityUtil.getValue(val, "phone"), EntityUtil.getValue(val, "content"),
                              EntityUtil.getValue(val, "subcode"), EntityUtil.getValue(val, "delivertime"))

# 短信上行消息报告接收-参数
class SmsDeliverParam:
    # 保留字段
    result = ""

    # 保留字段
    desc = ""

    # 数据集
    # 类型：List<SmsDeliverData>
    delivers = []

    def __init__(self, result, desc, delivers):
        self.result = result
        self.desc = desc
        self.delivers = delivers

    # class转字典
    def parseDict(self):
        temp = self.delivers
        res = {"result": self.result, "desc": self.desc, "delivers": []}
        for smsDeliverData in temp:
            res["delivers"].append(smsDeliverData.parseDict())
        return res

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        res = SmsDeliverParam(EntityUtil.getValue(val, "result"), EntityUtil.getValue(val, "desc"), [])
        if "delivers" in val.keys():
            for smsDeliverData in val["delivers"]:
                res.delivers.append(SmsDeliverData.parseObj(smsDeliverData))
        return res

# 短信下发状态报告参数
class SmsReportData:
    # 短信编号
    msgid = ""

    # 下行手机号码
    phone = ""

    # 短信发送结果：0——成功；1——接口处理失败；2——运营商网关失败
    status = ""

    # 状态报告描述
    desc = ""

    # 当status为1时, 表示平台返回错误码，参考:状态报告错误码。当status为0或2时，表示运营商网关返回的原始值
    wgcde = ""

    # 状态报告接收时间格式为yyyy-MM-dd HH:mm:ss
    time = ""

    #  客户提交时间格式为yyyy-MM-dd HH:mm:ss
    submitTime = ""

    #  大汉三通发送时间格式为yyyy-MM-dd HH:mm:ss
    sendTime = ""

    # 长短信条数（接口处理失败只给一条）
    smsCount = 0

    # 长短信序号
    smsIndex = 0

    def __init__(self, msgid, phone, status, desc, wgcde, time, submitTime, sendTime, smsCount, smsIndex):
        self.msgid = msgid
        self.phone = phone
        self.status = status
        self.desc = desc
        self.wgcde = wgcde
        self.time = time
        self.submitTime = submitTime
        self.sendTime = sendTime
        self.smsCount = smsCount
        self.smsIndex = smsIndex

    # class转字典
    def parseDict(self):
        return self.__dict__

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        return SmsReportData(EntityUtil.getValue(val, "msgid"), EntityUtil.getValue(val, "phone"),
                             EntityUtil.getValue(val, "status"), EntityUtil.getValue(val, "desc"),
                             EntityUtil.getValue(val, "wgcde"), EntityUtil.getValue(val, "time"),
                             EntityUtil.getValue(val, "submitTime"), EntityUtil.getValue(val, "sendTime"),
                             EntityUtil.getValue(val, "smsCount"), EntityUtil.getValue(val, "smsIndex"))

# 短信下发状态报告接收-参数
class SmsReportParam:
    # 保留字段
    result = ""
    
    # 保留字段
    desc = ""

    # 数据集
    # 类型：List<SmsReportData>
    reports = []

    def __init__(self,result,desc,reports):
        self.result = result
        self.result = desc
        self.result = reports

    # class转字典
    def parseDict(self):
        temp = self.reports
        res = {"result": self.result, "desc": self.desc, "reports": []}
        for smsReportData in temp:
            res["reports"].append(smsReportData.parseDict())
        return res

    # 将字典转换成class
    @staticmethod
    def parseObj(val):
        if type(val) != dict:
            raise Exception("val参数必须为字典类型")
        res = SmsReportParam(EntityUtil.getValue(val, "result"), EntityUtil.getValue(val, "desc"), [])
        if "reports" in val.keys():
            for smsReportData in val["reports"]:
                res.reports.append(SmsReportData.parseObj(smsReportData))
        return res